/**************************************************************************/
// * .do file for generating table of descriptive statistics and balance 
/**************************************************************************/

clear
set more off

/**************************************************************************/
			//SS-3//
/**************************************************************************/

use "$dta/SS3.dta", clear

*** label variables and set-up values codes amenable for output table ***

//recode 1/2 no/yes to 0/1 no/yes
recode gender (2 = 0 "Male") (1 = 1 "Female"), prefix(new)
la var newgender "Gender (1 = Female; 0 = Male)"

recode owner (2 = 1 "Yes") (1 = 0 "No"), prefix(new)
la var newowner "Owns land (1 = Yes; 0 = No)"

recode iscrp noncrp (2 = 1 "Yes") (1 = 0 "No"), prefix(new) label(yesno_new)
la var newiscrp "Participate in CRP (1 = Yes; 0 = No)"
la var newnoncrp "Any other conservation program (1 = Yes; 0 = No)"

gen anycrp = newiscrp == 1 | newnoncrp == 1
la var anycrp "Any conservation program (1 = Yes; 0 = No)"

recode damage (2 = 1 "Yes") (1 = 0 "No"), prefix(new)
la var newdamage "Any hog damage in past year? (1 = Yes; 0 = No)"

//other variable labels
la var age "Age"
la var agyears "Number of years in agriculture"
la var totalacres "Total agricultural land (acres)"
la var acresown "Acres owned"
la var acreslease "Acres leased"
la var acresrow "Acres under row crops"
la var acreshog "Acres damaged by hogs"

*mark obs. with no missing variables in covariates and with valid bids
gl balvars age agyears newgender newowner  newiscrp newnoncrp anycrp totalacres acresown acreslease  acresrow acreshog newdamage
	
#delimit ;
egen miss_count = rowmiss($balvars default fracbid) ;
#delimit cr
gen validobs = miss_count == 0

 
*f-test for joint orthogonality
reg default age agyears newgender newowner  newiscrp newnoncrp anycrp totalacres acresown acreslease  acresrow acreshog newdamage i.state  if validobs 

testparm  age agyears newgender newowner  newiscrp newnoncrp anycrp totalacres acresown acreslease  acresrow acreshog newdamage

* store fstat and p-value from above for use in table notes
local fstat: display %03.2f r(F)
local pval: display %03.2f r(p)


#delimit ;
iebaltab  age agyears newgender newowner  newiscrp newnoncrp anycrp
	totalacres acresown acreslease  acresrow acreshog newdamage if validobs ,
	grpvar(default) total  onerow rowvarlabels std format(%9.2f) nottest
	savetex("${outputs}/hogvisedesc_bidders.tex") 
	grplabels(0 Starting Bid = 0% @ 1 Starting Bid = 100%) 
	texcolwidth(6cm)
	tblnonote
	tblnote(Descriptive statistics shown are for the sample of participants who places bids. The F-test statistic for the test of joint equality of the covariates is `fstat' (p = `pval'). CRP stands for the US Conservation Reserve Program. "Any other conservation program" refers to participation in any non-CRP federal, state or local programs. "Any conservation program" refers to participation in either CRP or any other conservation program.)
	replace ;
#delimit cr 


/**************************************************************************/
			//SS I and II //
/**************************************************************************/


use "$dta/SS1and2.dta", clear

keep if realbid != .   // drop observations with no bids placed

recode gender (2 = 0 "Male") (1 = 1 "Female"), prefix(new)
la var newgender "Gender (1 = Female; 0 = Male)"

recode isowner (2 = 1 "Yes") (1 = 0 "No"), prefix(new)
la var newisowner "Owns land (1 = Yes; 0 = No)"

gen anycrp = crpindicator == 1 | noncrp == 1
la var anycrp "Any conservation program (1 = Yes; 0 = No)"

//other variable labels
la var age "Age"
la var productionyears "Number of years in agriculture"
la var totalacres "Total agricultural land (acres)"
la var numofacresowned "Acres owned"
la var numofacresleased "Acres leased"
la var rowcropacres "Acres under row crops"
la var isagweek "Participant in Ag. Week (1 = Yes; 0 = No)"
la var crpindicator "Participate in CRP (1 = Yes; 0 = No)"
la var noncrp "Any other conservation program (1 = Yes; 0 = No)"

*mark obs. with no missing variables
#delimit ;
gl balvars age productionyears   newgender 
	newisowner crpindicator noncrp anycrp totalacres numofacresowned numofacresleased   
	rowcropacres  isagweek ;
#delimit cr


**collapse to participant level
foreach v of var * {
 	local l`v' : variable label `v'
        if `"`l`v''"' == "" {
 		local l`v' "`v'"
  	}
  }


collapse (mean) $balvars agvise slidervariation , by(responseid)

foreach v of var * {
	label var `v' "`l`v''"
 }
 

egen miss_count = rowmiss($balvars slidervariation) 
gen validobs = miss_count == 0
keep if validobs

** Table of descriptive stats: SS I **

reg slidervariation age productionyears   newgender newisowner crpindicator noncrp anycrp totalacres numofacresowned numofacresleased   rowcropacres  isagweek if validobs & agvise == 1

testparm age productionyears   newgender newisowner crpindicator noncrp anycrp totalacres numofacresowned numofacresleased   rowcropacres  isagweek


local fstat: display %03.2f r(F)
local pval: display %03.2f r(p)


#delimit ;
iebaltab  age productionyears   newgender 
	newisowner crpindicator noncrp anycrp totalacres numofacresowned numofacresleased   
	rowcropacres  isagweek if validobs & agvise == 1 ,
	grpvar(slidervariation)  total  onerow rowvarlabels std format(%9.2f) nottest
	savetex("${outputs}/agvise1desc_bidders.tex") 
	grplabels(0 Starting Bid = 0% @ 1 Starting Bid = 100%) 
	texcolwidth(6cm)
	tblnonote
	tblnote(Descriptive statistics shown are for the sample of participants who placed bids. Note that each participant could bid on more than one technology. The F-test statistic for the test of joint equality of the covariates is `fstat' (p = `pval'). CRP stands for the US Conservation Reserve Program. ``Any other conservation program'' refers to participation in any non-CRP federal, state or local programs. ``Any conservation program'' refers to participation in either CRP or any other conservation program. Ag Week is a week-long agricultural event at the University of Delaware (where some producers were recruited).)
	replace ;
#delimit cr 


** Table of descriptive stats: SS II **

reg slidervariation age productionyears   newgender newisowner crpindicator noncrp anycrp totalacres numofacresowned numofacresleased   rowcropacres  isagweek if validobs & agvise == 2

testparm age productionyears   newgender newisowner crpindicator noncrp anycrp totalacres numofacresowned numofacresleased   rowcropacres  isagweek


local fstat: display %03.2f r(F)
local pval: display %03.2f r(p)


#delimit ;
iebaltab  age productionyears   newgender 
	newisowner crpindicator noncrp anycrp totalacres numofacresowned numofacresleased   
	rowcropacres  if validobs & agvise == 2 ,
	grpvar(slidervariation) total  onerow rowvarlabels std format(%9.2f) nottest
	savetex("${outputs}/agvise2desc_bidders.tex") 
	grplabels(0 Starting Bid = 0% @ 1 Starting Bid = 100%) 
	texcolwidth(6cm)
	tblnonote
	tblnote(Descriptive statistics shown are for the sample of participants who placed bids. Note that each participant could bid on more than one technology. The F-test statistic for the test of joint equality of the covariates is `fstat' (p = `pval'). CRP stands for the US Conservation Reserve Program. ``Any other conservation program'' refers to participation in any non-CRP federal, state or local programs. ``Any conservation program'' refers to participation in either CRP or any other conservation program.)
	replace ;
#delimit cr 

